<Project>
  <Import Project="../Directory.Build.targets" />
  <Import Project="$(MonoProjectRoot)\wasi\build\WasiApp.InTree.targets" />

  <PropertyGroup>
    <_SampleProject Condition="'$(_SampleProject)' == ''">$(MSBuildProjectFile)</_SampleProject>
    <_SampleAssembly Condition="'$(_SampleAssembly)' == ''">$(TargetFileName)</_SampleAssembly>
    <_SampleProjectName>$([System.String]::Copy('$(_SampleProject)').Replace('.csproj',''))</_SampleProjectName>
    <MONO_LOG_LEVEL Condition="false">--env MONO_LOG_LEVEL=debug --env MONO_LOG_MASK=all</MONO_LOG_LEVEL>
    <_ExeExt Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">.exe</_ExeExt>
  </PropertyGroup>

  <Target Name="RunSampleWithWasmtime" DependsOnTargets="Build">
    <!--
      TODOWASI - - tcplisten localhost:64000 - - env DEBUGGER_FD=4
    -->
    <Exec WorkingDirectory="bin/wasi-wasm/AppBundle"
          Condition="'$(WasmBuildNative)' != 'true'"
          Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) --dir . dotnet.wasm $(_SampleProjectName)" IgnoreExitCode="true" />
    <Exec WorkingDirectory="bin/wasi-wasm/AppBundle"
          Condition="'$(WasmBuildNative)' == 'true' and '$(WasmSingleFileBundle)' != 'true'"
          Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) --dir . dotnet.wasm" IgnoreExitCode="true" />
    <Exec WorkingDirectory="bin/wasi-wasm/AppBundle"
          Condition="'$(WasmSingleFileBundle)' == 'true'"
          Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) $([System.IO.Path]::ChangeExtension($(_SampleAssembly), '.wasm'))" IgnoreExitCode="true" />
  </Target>

  <Import Project="$(RepositoryEngineeringDir)testing\wasi-provisioning.targets" />
</Project>